#include <stdio.h>

#define MAX_LENGTH 20
#define IN_WORD    1
#define OUT_WORD   0
#define LOWER_A    97
#define LOWER_Z    122
#define UP_A       65
#define UP_Z       90

int printLine(int);

int wordLength() {

    printf("exercise for 1-13 in page 24\n");

    int n[MAX_LENGTH];
    char c;
    int wordLength;
    int inWord;

    inWord = OUT_WORD;
    wordLength = 0;

    for (int i = 0; i < MAX_LENGTH; i++) {
        n[i] = 0;
    }

    while ((c = getchar()) != EOF) {
        if ((c >= UP_A && c <= UP_Z) || (c >= LOWER_A && c <= LOWER_Z)) {
            inWord = IN_WORD;
            wordLength++;
        } else {
            if (wordLength <= MAX_LENGTH) {
                if (wordLength != 0 && inWord == IN_WORD) {
                    n[wordLength - 1]++;
                }
            } else {
                printf("单词太长( %d ), 不统计了。", wordLength);
            }
            inWord = OUT_WORD;
            wordLength = 0;
        }
    }

    for (int i = 0; i < MAX_LENGTH; i++) {
        printf("%2d | ", (i + 1));
        printLine(n[i]);
        printf("\n");
    }
}

int printLine(int len) {
    if (len > 0) {
        for (int i = 0; i < len; i++) {
            printf("=");
        }
    }
}
